<template>
  <div>
    <el-table :data="unExamineList" border style="width: 100%">
      <el-table-column prop="name" label="姓名" width="80"> </el-table-column>
      <el-table-column prop="bindId" label="绑定" width="90"> </el-table-column>
      <el-table-column prop="sex" label="性别" width="50"> </el-table-column>
      <el-table-column prop="university" label="学校"> </el-table-column>
      <el-table-column prop="academy" label="学院"> </el-table-column>
      <el-table-column prop="major" label="专业"> </el-table-column>
      <el-table-column prop="address" label="地址"> </el-table-column>
      <el-table-column prop="email" label="邮箱"> </el-table-column>
      <el-table-column prop="phone" label="电话"> </el-table-column>
      <el-table-column prop="roleId" label="申请权限" width="90">
        <template slot-scope="scope">
          <p>
            {{ scope.row.roleId == 1 ? '院级管理员' : '校级管理员' }}
          </p>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="160">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >批准</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >驳回</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  name: 'admin_List',
  data() {
    return {
      unExamineList: [],
      tableData: [],
    }
  },
  created() {
    this.loadList()
  },
  methods: {
    async loadList() {
      const { data: res } = await this.$http.get('/auth/selectUnExamine')
      this.unExamineList = res.data
    },
    async handleEdit(index, row) {
      const { data: res } = await this.$http.get('/auth/applicationApproval', {
        params: {
          uid: row.uid,
        },
      })
      if (res.code == 200) {
        this.$message.success(res.message)
      } else {
        this.$message.error(res.message)
      }
      this.loadList()
    },
    async handleDelete(index, row) {
      var that = this
      this.$prompt('请输入驳回理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      })
        .then(async ({ value }) => {
          if (value == '') {
            this.$message({
              type: 'error',
              message: '请填写理由',
            })
          } else {
            const { data: res } = await this.$http.post('/auth/refuseApply', {
              uid: row.uid,
              reason: value,
            })
            if (res.code == 200) {
              this.$message({
                type: 'success',
                message: res.message,
              })
              that.loadList()
            }
          }
        })
        .catch(() => {})
    },
  },
}
</script>
<style></style>
